//
//  LoginApi.swift
//  SeaTransportManage
//
//  Created by guopengwen on 2021/11/29.
//

import Foundation
import UIKit

extension GPRequestApi {
    // 司机登录
    func login(_ parameters: [String: Any], handler: @escaping ApiCompleted){
        request_post("\(kServiceHost)/prod-api/client/login", parameters: parameters, completed: handler)
    }
    
    // 修改密码
    func updatePassword(_ parameters: [String: Any], handler: @escaping ApiCompleted){
        request_put("\(kServiceHost)/prod-api/client/updatePass", parameters: parameters, completed: handler)
    }
    
    // 修改用户信息
    func updateUserInfo(_ parameters: [String: Any], handler: @escaping ApiCompleted){
        request_put("\(kServiceHost)/prod-api/client/edit", parameters: parameters, completed: handler)
    }
    
    // 司机信息
    func getUserInfo (handler: @escaping ApiCompleted) {
        request_get("\(kServiceHost)/prod-api/client/info", parameters: [:], completed: handler)
    }
    
    // 司机上传头像
    func updateAvatar(_ image: UIImage, handler: @escaping ApiCompleted){
        let data = image.jpegData(compressionQuality: 0.1)
        request_uploadWithFile("\(kServiceHost)/prod-api/client/avatar", data: data!, completed: handler)
    }
    
    // 待处理订单
    func getCurrentWaitOrder (handler: @escaping ApiCompleted) {
        request_get("\(kServiceHost)/prod-api/client/order/current", parameters: [:], completed: handler)
    }
    
    // 拒绝单
    func refusedOrder(_ parameters: [String: Any], handler: @escaping ApiCompleted){
        let orderId = parameters["orderId"] as! Int
        request_put("\(kServiceHost)/prod-api/client/refused/\(orderId)", parameters: parameters, completed: handler)
    }
    
    // 接单
    func acceptOrder(_ parameters: [String: Any], handler: @escaping ApiCompleted){
        let orderId = parameters["orderId"] as! Int
        request_put("\(kServiceHost)/prod-api/client/accept/\(orderId)", parameters: parameters, completed: handler)
    }
    
    // 订单详情
    func getOrderDetail (_ parameters: [String: Any], handler: @escaping ApiCompleted) {
        let orderId = parameters["orderId"] as! Int
        request_get("\(kServiceHost)/prod-api/client/order/\(orderId)", parameters: [:], completed: handler)
    }
    
    // 历史订单 
    func getHistoryOrderList (_ parameters: [String: Any], handler: @escaping ApiCompleted) {
        request_get("\(kServiceHost)/prod-api/client/order/his", parameters: parameters, completed: handler)
    }
    
    // 运单单个上传图片 
    func uploadrSinglePic(_ image: UIImage, handler: @escaping ApiCompleted) {
        let data = image.jpegData(compressionQuality: 0.1)
        request_uploadWithFile("\(kServiceHost)/prod-api/client/order/upload", data: data!, completed: handler)
    }
    
    // 阶段提交订单
    func submitOrder(_ parameters: [String: Any], handler: @escaping ApiCompleted){
        request_post("\(kServiceHost)/prod-api/client/order/submit", parameters: parameters, completed: handler)
    }
    
    // 文件信息
    func downLoadorderFile (_ parameters: [String: Any], handler: @escaping ApiCompleted) {
        let fileNo = parameters["fileNo"] as! String
        request_get("\(kServiceHost)/prod-api/client/order/file/\(fileNo)", parameters: [:], completed: handler)
    }
}
